package com.appwoo.txtws.activity;

import android.app.WallpaperManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.appwoo.txtws.adapter.WallpaperListAdapter;
import com.appwoo.txtws.adapter.WallpaperListAdapter.DownloadImageTask;
import com.appwoo.txtws.adapter.WallpaperListAdapter.DownloadImageTaskAfter;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.WallpaperBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.ImageHelper;
import com.appwoo.txtws.component.Logger;
import java.io.IOException;

public class SetWallpaperActivity extends AppActivity
  implements View.OnClickListener
{
  public static final String WALLPAPER_TYPE = "wallpaperType";
  public static final String WALLPAPER_VALUE = "wallpaperValue";
  private int height;
  private Button mBtnSetWallpaper;
  private DBHelper mDBHelper;
  private ImageView mIvShowWallpaper;
  private Bitmap wallpaper;
  private int wallpaperId;
  private String wallpaperType;
  private String wallpaperValue;
  private WallpaperBean wb;
  private int width;

  private void findView()
  {
    this.mIvShowWallpaper = ((ImageView)findViewById(2131493452));
    this.mBtnSetWallpaper = ((Button)findViewById(2131493451));
  }

  private void init()
  {
    Intent localIntent = getIntent();
    this.wallpaperType = localIntent.getStringExtra("wallpaperType");
    this.wallpaperValue = localIntent.getStringExtra("wallpaperValue");
    if (!"phoneAlbum".equals(this.wallpaperType))
    {
      this.wallpaperId = Integer.valueOf(this.wallpaperValue).intValue();
      this.wb = this.mDBHelper.getWallpaperById(this.wallpaperId);
    }
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    this.width = localDisplayMetrics.widthPixels;
    this.height = localDisplayMetrics.heightPixels;
  }

  private void initActionBar()
  {
    hideBarHome();
    setBarTitle(getResources().getString(2131427431));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        SetWallpaperActivity.this.finish();
      }
    });
  }

  private void setView()
  {
    this.mBtnSetWallpaper.setEnabled(false);
    if ((this.wb != null) && ("appInner".equals(this.wb.getType())))
    {
      this.wallpaperValue = this.wb.getName();
      this.mIvShowWallpaper.setBackgroundResource(getResources().getIdentifier(this.wb.getName(), "drawable", getApplicationInfo().packageName));
      this.mBtnSetWallpaper.setEnabled(true);
    }
    while (true)
    {
      this.mBtnSetWallpaper.setOnClickListener(this);
      return;
      if ((this.wb != null) && ("web".equals(this.wb.getType())))
      {
        this.wallpaperType = "phoneAlbum";
        if ((this.wb.getLocalLarge() == null) || ("".equals(this.wb.getLocalLarge())))
        {
          if (!isNetworkAvailable(this))
          {
            alertMessage(getString(2131428051));
          }
          else
          {
            WallpaperListAdapter localWallpaperListAdapter = new WallpaperListAdapter();
            WallpaperListAdapter.DownloadImageTaskAfter local1 = new WallpaperListAdapter.DownloadImageTaskAfter()
            {
              public void doOther(String paramAnonymousString)
              {
                SetWallpaperActivity.this.mIvShowWallpaper.invalidate();
                SetWallpaperActivity.this.wallpaperValue = SetWallpaperActivity.this.wb.getLocalLarge();
                SetWallpaperActivity.this.wallpaper = ImageHelper.getBitmapFromFile(SetWallpaperActivity.this.wallpaperValue, SetWallpaperActivity.this.mIvShowWallpaper.getWidth(), SetWallpaperActivity.this.mIvShowWallpaper.getHeight());
                SetWallpaperActivity.this.mIvShowWallpaper.setBackgroundDrawable(new BitmapDrawable(SetWallpaperActivity.this.wallpaper));
                SetWallpaperActivity.this.mBtnSetWallpaper.setEnabled(true);
              }
            };
            localWallpaperListAdapter.getClass();
            new WallpaperListAdapter.DownloadImageTask(localWallpaperListAdapter, this.mIvShowWallpaper, this.wb, this, "aa", local1).execute(new String[] { "" });
          }
        }
        else
        {
          this.wallpaper = ImageHelper.getBitmapFromFile(this.wb.getLocalLarge(), this.width, this.height);
          this.mIvShowWallpaper.setImageBitmap(this.wallpaper);
          this.wallpaperValue = this.wb.getLocalLarge();
          this.mBtnSetWallpaper.setEnabled(true);
        }
      }
      else if ("phoneAlbum".equals(this.wallpaperType))
      {
        this.wallpaper = ImageHelper.getBitmapFromFile(this.wallpaperValue, this.width, this.height);
        this.mIvShowWallpaper.setImageBitmap(this.wallpaper);
        this.mBtnSetWallpaper.setEnabled(true);
      }
    }
  }

  private void writeToSP()
  {
    SharedPreferences.Editor localEditor = getSharedPreferences("wallpaper", 0).edit();
    localEditor.putString("wallpaperType", this.wallpaperType);
    localEditor.putString("wallpaperValue", this.wallpaperValue);
    localEditor.commit();
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      return;
    case 2131493451:
    }
    WallpaperManager localWallpaperManager = WallpaperManager.getInstance(this);
    if ("appInner".equals(this.wallpaperType));
    while (true)
    {
      try
      {
        localWallpaperManager.setResource(getResources().getIdentifier(this.wb.getName(), "drawable", getApplicationInfo().packageName));
        writeToSP();
        Toast.makeText(this, 2131427435, 0).show();
        finish();
        return;
      }
      catch (IOException localIOException2)
      {
        localIOException2.printStackTrace();
        continue;
      }
      try
      {
        if (this.wallpaper == null)
          break label125;
        localWallpaperManager.setBitmap(this.wallpaper);
      }
      catch (IOException localIOException1)
      {
        localIOException1.printStackTrace();
      }
      continue;
      label125: Logger.e(SetWallpaperActivity.class.getName(), "壁纸设置失败");
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903189);
    this.mDBHelper = new DBHelper(this);
    initActionBar();
    init();
    findView();
    setView();
  }

  protected void onDestroy()
  {
    super.onDestroy();
    if (this.wallpaper != null)
      this.wallpaper.recycle();
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.SetWallpaperActivity
 * JD-Core Version:    0.6.2
 */